def __init__(self):
controller.ControllerFactory.__init__(self)
-
- self.majorTypes = [ CMSG_BLKIF_BE ]
-
- self.subTypes = {
- CMSG_BLKIF_BE_DRIVER_STATUS_CHANGED: self.recv_be_driver_status_changed,
- }
+ self.addMethod(CMSG_BLKIF_BE,
+ CMSG_BLKIF_BE_DRIVER_STATUS_CHANGED,
+ self.recv_be_driver_status_changed)
self.attached = 1
self.registerChannel()
def __init__(self, factory, dom):
controller.Controller.__init__(self, factory, dom)
self.devices = {}
-
- self.majorTypes = [ CMSG_BLKIF_FE ]
-
- self.subTypes = {
- CMSG_BLKIF_FE_DRIVER_STATUS_CHANGED:
- self.recv_fe_driver_status_changed,
- CMSG_BLKIF_FE_INTERFACE_CONNECT :
- self.recv_fe_interface_connect,
- }
+ self.addMethod(CMSG_BLKIF_FE,
+ CMSG_BLKIF_FE_DRIVER_STATUS_CHANGED,
+ self.recv_fe_driver_status_changed)
+ self.addMethod(CMSG_BLKIF_FE,
+ CMSG_BLKIF_FE_INTERFACE_CONNECT,
+ self.recv_fe_interface_connect)
self.attached = 1
self.evtchn = None
self.registerChannel()
def __init__(self, factory, dom, console_port):
controller.Controller.__init__(self, factory, dom)
- self.majorTypes = [ CMSG_CONSOLE ]
+ self.addMethod(CMSG_CONSOLE, 0, None)
self.status = self.STATUS_NEW
self.addr = None
self.conn = None
import channel
from messages import msgTypeName, printMsg
-DEBUG = 0
+DEBUG = 1
class Responder:
"""Handler for a response to a message with a specified id.
@ivar dom: the domain we are a control interface for
@type dom: int
@ivar majorTypes: major message types we are interested in
- @type majorTypes: [int]
- @ivar subTypes: mapping of message subtypes to methods
- @ivar subTypes: {int:method}
+ @type majorTypes: {int:{int:method}}
@ivar timeout: timeout (in seconds) for message handlers
@type timeout: int
def __init__(self):
self.channelFactory = channel.channelFactory()
- self.majorTypes = [ ]
- self.subTypes = {}
+ self.majorTypes = {}
self.dom = None
self.channel = None
self.idx = None
def setTimeout(self, timeout):
self.timeout = timeout
+ def getMethod(self, type, subtype):
+ """Get the method for a type and subtype.
+
+ @param type: major message type
+ @param subtype: minor message type
+ @return: method or None
+ """
+ method = None
+ subtypes = self.majorTypes.get(type)
+ if subtypes:
+ method = subtypes.get(subtype)
+ return method
+
+ def addMethod(self, type, subtype, method):
+ """Add a method to handle a message type and subtype.
+
+ @param type: major message type
+ @param subtype: minor message type
+ @param method: method
+ """
+ subtypes = self.majorTypes.get(type)
+ if not subtypes:
+ subtypes = {}
+ self.majorTypes[type] = subtypes
+ subtypes[subtype] = method
+
+ def getMajorTypes(self):
+ """Get the list of major message types handled.
+ """
+ return self.majorTypes.keys()
+
def requestReceived(self, msg, type, subtype):
"""Dispatch a request message to handlers.
Called by the channel for requests with one of our types.
if DEBUG:
print 'requestReceived>',
printMsg(msg, all=1)
- method = self.subTypes.get(subtype)
+ method = self.getMethod(type, subtype)
if method:
method(msg, 1)
elif DEBUG:
printMsg(msg, all=1)
if self.callResponders(msg):
return
- method = self.subTypes.get(subtype)
+ method = self.getMethod(type, subtype)
if method:
method(msg, 0)
elif DEBUG:
self.channel = self.channelFactory.domChannel(self.dom)
self.idx = self.channel.getIndex()
if self.majorTypes:
- self.channel.registerDevice(self.majorTypes, self)
+ self.channel.registerDevice(self.getMajorTypes(), self)
def deregisterChannel(self):
"""Deregister interest in our major message types with the
def __init__(self):
controller.ControllerFactory.__init__(self)
-
- self.majorTypes = [ CMSG_NETIF_BE ]
-
- self.subTypes = {
- CMSG_NETIF_BE_DRIVER_STATUS_CHANGED: self.recv_be_driver_status_changed,
- }
+ self.addMethod(CMSG_NETIF_BE,
+ CMSG_NETIF_BE_DRIVER_STATUS_CHANGED,
+ self.recv_be_driver_status_changed)
self.attached = 1
self.registerChannel()
controller.Controller.__init__(self, factory, dom)
self.devices = {}
- self.majorTypes = [ CMSG_NETIF_FE ]
-
- self.subTypes = {
- CMSG_NETIF_FE_DRIVER_STATUS_CHANGED:
- self.recv_fe_driver_status_changed,
- CMSG_NETIF_FE_INTERFACE_CONNECT :
- self.recv_fe_interface_connect,
- }
+ self.addMethod(CMSG_NETIF_FE,
+ CMSG_NETIF_FE_DRIVER_STATUS_CHANGED,
+ self.recv_fe_driver_status_changed)
+ self.addMethod(CMSG_NETIF_FE,
+ CMSG_NETIF_FE_INTERFACE_CONNECT,
+ self.recv_fe_interface_connect)
self.registerChannel()
def sxpr(self):